package com.tianji.remark.task;


import com.tianji.remark.service.ILikedRecordService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
@RequiredArgsConstructor
public class LikedTimesCheckTask {

    private static final List<String> BIZ_TYPE = List.of("QA", "NOTE");
    private static final int MAX_BIZ_SIZE = 30; // 任务每次取的Biz数量 防止MQ一次发送消息太多

    private final ILikedRecordService likedRecordService;

    // 每20s执行一次 将redis中业务类型下面 某业务的点赞总数 发送消息到mq
//    @Scheduled(cron = "0/20 * * * * ?") // 每间隔20s执行一次
    @XxlJob("checkLikedTimes")
    public void checkLikedTimes(){
        for (String bizType : BIZ_TYPE) {
            likedRecordService.readLikedTimesAndSendMessage(bizType, MAX_BIZ_SIZE);
        }
    }

}
